package com.demo.swingquickticket.swing.view.account.user;

import com.demo.swingquickticket.swing.model.AppJTableModel;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class UserDetailPanel extends JPanel {

    private static final UserDetailPanel INSTANCE = new UserDetailPanel();

    private JButton addBtn;
    private JButton delBtn;
    private JButton upBtn;
    private JButton reBtn;
    private JTable detailTable;

    private UserDetailPanel() {
        init();
        bind();
    }

    public static UserDetailPanel getInstance () {
        return INSTANCE;
    }

    private void init() {

        JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,5));

        addBtn = new JButton("新增");
        delBtn = new JButton("删除");
        upBtn = new JButton("修改");
        reBtn = new JButton("刷新");

        btnPanel.add(addBtn);
        btnPanel.add(delBtn);
        btnPanel.add(upBtn);
        btnPanel.add(reBtn);

        AppJTableModel appJTableModel = new AppJTableModel();
        List<String> header = Arrays.asList("姓名");
        appJTableModel.setHeader(header);
        detailTable = new JTable(appJTableModel);
        JScrollPane tablePanel = new JScrollPane(detailTable);

        this.setLayout(new BorderLayout());
        this.add(btnPanel, BorderLayout.NORTH);
        this.add(tablePanel, BorderLayout.CENTER);
        this.setVisible(true);
    }

    private void bind() {
        addBtn.addActionListener(e -> {

        });
        delBtn.addActionListener(e -> {

        });
        upBtn.addActionListener(e -> {

        });
        reBtn.addActionListener(e -> {

        });
    }

}
